package com.tgy.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.tgy.admin.Service.AdminUserService;
import com.tgy.page.PageQuery;
import com.tgy.pojo.BlogUser;
import com.tgy.result.GraceJSONResult;
import com.tgy.result.LayuiTableResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author tianguiyin
 * @version 1.0
 * @date 2022/6/21 21:01
 */
@Validated
@Api(value = "博客用户控制器", tags = {"博客用户管理"})
@RestController
@RequestMapping("/admin/blogUser")
public class AdminUserController {

    @Resource
    private AdminUserService adminUserService;

    @ApiOperation("获取博客用户列表")
    @SaCheckPermission("blogUser:update")
    @GetMapping("getBlogUserList")
    public LayuiTableResult getBlogUserList(BlogUser bo, PageQuery pageQuery){
        return adminUserService.getBlogUserList(bo,pageQuery);
    }

    @ApiOperation("修改博客用户状态")
    @SaCheckPermission("blogUser:update")
    @PostMapping("updateStatus")
    public GraceJSONResult updateStatus(BlogUser bo){
        return adminUserService.updateStatus(bo.getId(),bo.getStatus());
    }

    @ApiOperation("重置密码")
    @SaCheckPermission("blogUser:update")
    @PostMapping("resetPassword")
    public GraceJSONResult resetPassword(String id){
        return adminUserService.resetPassword(id);
    }


    @ApiOperation("添加博客用户")
    @SaCheckPermission("blogUser:add")
    @PostMapping("addBlogUser")
    public GraceJSONResult addBlogUser(BlogUser bo){
        return adminUserService.addBlogUser(bo);
    }

    @ApiOperation("修改博客用户")
    @SaCheckPermission("blogUser:update")
    @PostMapping("updateBlogUser")
    public GraceJSONResult updateBlogUser(BlogUser bo){
        return adminUserService.updateBlogUser(bo);
    }

    @ApiOperation("删除博客用户")
    @SaCheckPermission("blogUser:del")
    @PostMapping("delBlogUser")
    // @PostMapping("delBlogAdminUser/{id}")
    public GraceJSONResult delBlogUser(@ApiParam("ID必须传入") String id){
        return adminUserService.delBlogUser(id);
    }

    @ApiOperation("批量删除博客用户")
    @SaCheckPermission("blogUser:del")
    @PostMapping("delBlogUserIds")
    public GraceJSONResult delBlogUserIds(@ApiParam("ids必须传入") String ids){
        List<String> list = new ArrayList<>(Arrays.asList(ids.split(",")));
        return adminUserService.delBlogUserIds(list);
    }

    @ApiOperation("根据ID查询博客用户")
    @SaCheckPermission
    @PostMapping("getBlogUserById")
    public GraceJSONResult getBlogUserById(@ApiParam("ID必须传入") String id){
        return adminUserService.getBlogUserById(id);
    }


    @ApiOperation("根据ID查询博客用户")
    @SaCheckPermission
    @GetMapping("getBlogUserListNotPage")
    public GraceJSONResult getBlogUserListNotPage(String articleId){
        return GraceJSONResult.ok(adminUserService.getBlogUserById(articleId));
    }


}
